# coding:utf-8

import numpy as np
import pandas


# 01
def create_arr():
    arr = np.array([[1, 2, 3], [4, 5, 6]])
    return arr


def create_arr2():
    arr = np.ndarray(shape=(2, 3), dtype=np.int)
    return arr


# arr = create_arr()
# arr2 = create_arr2()
# print(type(arr), type(arr.dtype))  # <class 'numpy.ndarray'> <class 'numpy.dtype'>
# print(arr)
# # [[1 2 3]
# #  [4 5 6]]
# print(type(arr2), type(arr2.dtype))
# print(arr2)
# <class 'numpy.ndarray'> <class 'numpy.dtype'>
# [[27676432        0        0]
#  [       0        0        0]]


# 02
# dt = np.dtype(np.int)
# print(type(dt), dt)
# <class 'numpy.dtype'> int64

# dt = np.dtype(np.intc)
# print(type(dt), dt)
# <class 'numpy.dtype'> int32

dt_obj = np.dtype([('name', np.str)])
print(type(dt_obj), dt_obj)

dt_age = np.dtype([('age', np.int_)])
print(type(dt_age), dt_age)

dt_score = np.dtype([('score', np.float_)])
print(type(dt_score), dt_score)
# <class 'numpy.dtype'> [('name', '<U')]
# <class 'numpy.dtype'> [('age', '<i8')]
# <class 'numpy.dtype'> [('score', '<f8')]

print()
stu = np.dtype([('name', np.str_), ('age', np.int), ('score', np.float)])
print(type(stu), stu)
# <class 'numpy.dtype'> [('name', '<U'), ('age', '<i8'), ('score', '<f8')]

print()
stu_list = np.array([('Tom', 21, 60), ('Yan', 20, 59)], dtype=stu)
# TODO why
print(type(stu_list), stu_list)
# <class 'numpy.ndarray'> [('', 21, 60.) ('', 20, 59.)]


